//
//  UIImage+Extension.swift
//  swift_demo_weibo
//
//  Created by 杨兵 on 15/5/22.
//  Copyright (c) 2015年 bing. All rights reserved.
//

import UIKit

extension UIImage {
    
    // 根据宽度绘制图片
    func scaleImage(#width :CGFloat) -> UIImage {
        // 获取大小
        let height = width * size.height /  size.width
        let localsize = CGSizeMake(width, height)
        
        // 开启一个图形上下文
        UIGraphicsBeginImageContext(localsize)
        
        self.drawInRect(CGRect(origin: CGPointZero, size: localsize))
        
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        
        // 结束图形上下文
        UIGraphicsEndImageContext()
        
        return newImage
        
    }
    
}
